﻿using System.Data.SqlClient;
using Kogel.Dapper.Extension;

namespace QBData
{
    /// <summary>
    /// 数据库上下文
    /// </summary>
    public class DBContext
    {
        /// <summary>
        /// 数据库连接字符串
        /// </summary>
        public static readonly string connectionStr = @"data source=DESKTOP-7C4MUKF\SQLSEVER;initial catalog=QBSystem;persist security info=True;user id=Sa;password=asd123;MultipleActiveResultSets=True;App=EntityFramework";

        private static SqlConnection _db;
        /// <summary>
        /// 数据库连接对象
        /// </summary>
        public static SqlConnection DB
        {
            get
            {
                if (_db == null)
                {
                    _db = new SqlConnection(connectionStr);

                    //实体类预加载
                    EntityCache.Register("QBData");
                }
                return _db;
            }
        }
    }
}
